package com.cocotea.context;

import com.cocotea.valid.constant.MessageConstant;
import com.cocotea.valid.ValidMain;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.reflect.MethodSignature;

public class AutoValidStarterContext {

    public Object cut(ProceedingJoinPoint pjp) throws Throwable {
        String validMessage = ValidMain.valid(
                ((MethodSignature) pjp.getSignature()).getMethod().getParameterTypes(),
                pjp.getArgs()
        );
        if (MessageConstant.SUCCESS.equals(validMessage)) {
            return pjp.proceed();
        } else {
            return validMessage;
        }
    }

}
